function [trial,conf]=run_task(task,stim,frame,varargin)
% Run a block of trial of a given task
n_trials = length(stim);

w=frame.ptr;
rect=frame.rect;
% Run a trial of the task
for i=1:n_trials    
    if nargout>1
        [trial(i),conf(i)] = run_trial_confidence(task,stim(i),w);    
    else
        [trial(i)] = run_trial(task,stim(i),w);
    end       
    Screen('flip',frame.ptr);
    WaitSecs(.5+rand/2);

end 
